package com.testitems.common.web.page;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

@Slf4j
@Data
@ApiModel("分页结果对象")
public class PageInfo<T> implements Serializable {

    @ApiModelProperty("总行数")
    private long total = 0;

    @ApiModelProperty("数据列表")
    private List<T> records = Collections.emptyList();

    @ApiModelProperty(value = "页码")
    private Long current;

    @ApiModelProperty(value = "页大小")
    private Long size;

    public PageInfo() {

    }

    public PageInfo(IPage<T> page) {
        this.total = page.getTotal();
        this.records = page.getRecords();
        this.current = page.getCurrent();
        this.size = page.getSize();
    }

    public static <T> PageInfo<T> get(IPage<T> page) {
        return new PageInfo<>(page);
    }
}
